<?php
defined('IN_ADMIN') or exit('No permission resources.');
include $this->admin_tpl('header','admin');
?>
<style>
#add_sale {width:100px; height:24px; position:absolute; top:10px; right:8px; overflow:hidden; background:url(<?php echo IMG_PATH; ?>admin_img/icon_add.gif) no-repeat left center; border:1px solid #DDD;}
#add_sale a {display:block; padding-left:20px; line-height:190%;}
div.table-list th { font-weight:normal; padding:5px 0 5px 0;}
.none {border:0; background:none repeat scroll 0 0 transparent;}
</style>
<div id="add_sale"><a href="#" onclick="add()">添加红包类型</a></div>
<form action="?m=ushop&c=bonus&a=init&menuid=<?php echo $_GET['menuid'];?>" method="post" id="sale_form">
<div class="table-list" style="width:99%; margin:auto;">
<table width="100%" cellspacing="0">
<thead>
	<tr>
		<th width="10%" align="center"><input type="checkbox" value="" id="check_box" onclick=""></th>
		<th width="15%" align="center">类型名称&nbsp;
			<a href="javascript:alse_sort('type_name','desc')"><img src="<?php echo IMG_PATH ;?>admin_img/sort_desc.gif" /></a>&nbsp;
			<a href="javascript:alse_sort('type_name','asc')"><img src="<?php echo IMG_PATH ;?>admin_img/sort_asc.gif" /></a>
		</th>
		<th width="15%" align="center">发放类型&nbsp;
			<a href="javascript:alse_sort('send_type','desc')"><img src="<?php echo IMG_PATH ;?>admin_img/sort_desc.gif" /></a>&nbsp;
			<a href="javascript:alse_sort('send_type','asc')"><img src="<?php echo IMG_PATH ;?>admin_img/sort_asc.gif" /></a>
		</th>
		<th width="13%" align="center">红包金额&nbsp;
			<a href="javascript:alse_sort('type_money','desc')"><img src="<?php echo IMG_PATH ;?>admin_img/sort_desc.gif" /></a>&nbsp;
			<a href="javascript:alse_sort('type_money','asc')"><img src="<?php echo IMG_PATH ;?>admin_img/sort_asc.gif" /></a>
		</th>
		<th width='10%' align="center">订单下限&nbsp;
			<a href="javascript:alse_sort('min_amount','desc')"><img src="<?php echo IMG_PATH ;?>admin_img/sort_desc.gif" /></a>&nbsp;
			<a href="javascript:alse_sort('min_amount','asc')"><img src="<?php echo IMG_PATH ;?>admin_img/sort_asc.gif" /></a>
		</th>
		<input type="hidden" name="sale_order" value="" id="sale_order" />
		<th width="10%" align="center">发放数量</th>
		<th width="10%" align="center">使用数量</th>
		<th width="27%" align="center">操作</th>
	</tr>
</thead>
<?php
if(is_array($infos) && !empty($infos)){
	foreach($infos as $info){
?>
	<tr id="con">
    
    	<th width="10%" align="center"><input type="checkbox" name="mid[]" value="<?php echo $info['type_id']?>"></th>
        <th width="15%" align="center"><input type="text" value="<?php echo $info['type_name'] ?>" onchange="change('<?php echo $info['type_id'] ?>','0',$(this).val())" onfocus="$(this).removeClass('none')" onblur="$(this).addClass('none')" class="none" /></th>
        <th width="15%" align="center"><?php echo $info['send_type'] ?></th>
        <th width="13%" align="center"><input type="text" value="<?php echo $info['type_money'] ?>" onchange="change('<?php echo $info['type_id'] ?>','1',$(this).val())" onfocus="$(this).removeClass('none')" onblur="$(this).addClass('none')" class="none" /></th>
        <th width='10%' align="center"><input type="text" value="<?php echo $info['min_goods_amount'] ?>" onchange="change('<?php echo $info['type_id'] ?>','2',$(this).val())" onfocus="$(this).removeClass('none')" onblur="$(this).addClass('none')" class="none" /></th>
        <th width="10%" align="center"><?php echo $info['send_time'] ?></th>
        <th width="10%" align="center"><?php echo $info['used_time'] ?></th>
        <th width="27%" align="center">
        <?php
			if($info['send_type'] == '按用户发送') {
		?>	
			<?php if($info['send_true'] == 0) {?>
        	<a href="#" onclick="sendfalse()">发放</a>&nbsp;
			<?php }else{ ?>
			<a href="#" onclick="send('<?php echo $info['type_id']; ?>','0')">发放</a>&nbsp;
			<?php }?>			
            <a href="?m=ushop&c=bonus&a=bonus_list&type=0&mid=<?php echo $info['type_id']; ?>&menuid=<?php echo $_GET['menuid'];?>">查看</a>&nbsp;
            <a href="#" onclick="edit('<?php echo $info['type_id']; ?>','<?php echo $info['type_name']; ?>')">编辑</a>&nbsp;
            <a href="?m=ushop&c=bonus&a=delete&mid=<?php echo $info['type_id']; ?>">移除</a>&nbsp;
        <?php
			}elseif($info['send_type'] == '按商品发放') {
		?>
			<?php if($info['send_true'] == 0) {?>
        	<a href="#" onclick="sendfalse()">发放</a>&nbsp;
			<?php }else{ ?>
			<a href="#" onclick="send('<?php echo $info['type_id']; ?>','1')">发放</a>&nbsp;
			<?php }?>
            <a href="?m=ushop&c=bonus&a=bonus_list&type=1&mid=<?php echo $info['type_id']; ?>&menuid=<?php echo $_GET['menuid'];?>">查看</a>&nbsp;
            <a href="#" onclick="edit('<?php echo $info['type_id']; ?>','<?php echo $info['type_name']; ?>')">编辑</a>&nbsp;
            <a href="?m=ushop&c=bonus&a=delete&mid=<?php echo $info['type_id']; ?>">移除</a>&nbsp;
        <?php
			}elseif($info['send_type'] == '按订单金额发送'){
		?>
            <a href="#" onclick="edit('<?php echo $info['type_id']; ?>','<?php echo $info['type_name']; ?>')">编辑</a>&nbsp;
            <a href="?m=ushop&c=bonus&a=delete&mid=<?php echo $info['type_id']; ?>">移除</a>&nbsp;
		<?php
			}
		?>
        </th>
	</tr>
<?php
	}
}else if(empty($infos)) {
?>
	<tr>
    	<td colspan="8" align="center">没有找到任何记录</td>
    </tr>
<?php	
}
?>
</table>
</div>
<div class="btn">
    <a href="#" onClick="javascript:$('input[type=checkbox]').attr('checked', true)"><?php echo L('selected_all')?></a>/
    <a href="#" onClick="javascript:$('input[type=checkbox]').attr('checked', false)"><?php echo L('cancel')?></a>
    <input name="dosubmit" type="submit" class="button" value="删除选中" onclick="return confirm('<?php echo L('confirm', array('message' => L('selected')))?>');">&nbsp;&nbsp;
</div>
<div id="pages"><?php echo $pages?></div>
</form>
<script>
	$("input[value='删除选中']").live('mousedown',function() {
		document.getElementById("sale_form").action = "?m=ushop&c=bonus&a=delete";
	})
	$("#con th input").live('mouseover',function() {
		this.style.color="#004499"
	}).live('mouseout',function() {
		this.style.color="#000"
	})
	function change(id,type,value) {
		if(value == "" || value == null || value == undefined ) {
			alert('内容不能为空');
			return false;
		}
		$.post("?m=ushop&c=bonus&a=public_mouse_edit",{id:id,type:type,value:value})
	}
	function alse_sort(sort_by,sort_order) {
		document.getElementById('sale_order').value = sort_by+'&'+sort_order;
		document.getElementById('sale_form').submit();
	}
	function edit(id, name) {
		window.top.art.dialog({id:'edit'}).close();
		window.top.art.dialog({title:'<?php echo L('edit')?> '+name+' ',id:'edit',iframe:'?m=ushop&c=bonus&a=edit&mid='+id,width:'700',height:'400'}, function(){var d = window.top.art.dialog({id:'edit'}).data.iframe;var form = d.document.getElementById('dosubmit'); form.click();return false;}, function(){window.top.art.dialog({id:'edit'}).close()});
	}
	function send(id,type) {
		window.top.art.dialog({id:'edit'}).close();
		window.top.art.dialog({title:'发送红包',id:'edit',iframe:'?m=ushop&c=bonus&a=send_by&type='+type+'&mid='+id,width:'700',height:'400'}, function(){var d = window.top.art.dialog({id:'edit'}).data.iframe;var form = d.document.getElementById('dosubmit'); form.click();return false;}, function(){window.top.art.dialog({id:'edit'}).close()});
	}
	function add() {
		window.top.art.dialog({id:'edit'}).close();
		window.top.art.dialog({title:'添加红包',id:'edit',iframe:'?m=ushop&c=bonus&a=add_sale',width:'700',height:'400'}, function(){var d = window.top.art.dialog({id:'edit'}).data.iframe;var form = d.document.getElementById('dosubmit'); form.click();return false;}, function(){window.top.art.dialog({id:'edit'}).close()});
	}
	function sendfalse() {
		window.top.art.dialog({title:'发送失败',id:'sendfalse',content:'发放时间已过，请修改',width:'300',height:'100'}, function(){window.top.art.dialog({id:'edit'}).close()}, function(){window.top.art.dialog({id:'edit'}).close()});
	}
</script>
</body>
</html>